package com.luoshengsha.springboot.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

import com.luoshengsha.springboot.bean.User;
import com.luoshengsha.springboot.repository.UserRepository;
import com.luoshengsha.springboot.service.UserService;

import jakarta.annotation.Resource;

/**
 * 用户接口实现
 */
@Service
public class UserServiceImpl implements UserService {
	@Resource
	private UserRepository userRepository;

	@Override
	public User save(User user) {
		System.out.println("保存用户");
		return userRepository.save(user);
	}

	@Override
	public User find(Long id) {
		// TODO Auto-generated method stub
		System.out.println("查找用户");
		
		// 如果没有找到对应的用户，则返回null
		return userRepository.findById(id).orElse(null);
	}

	@Override
	public void delete(Long id) {
		// TODO Auto-generated method stub
		System.out.println("删除用户");
		userRepository.deleteById(id);;
	}

	@Override
	public List<User> list() {
		// TODO Auto-generated method stub
		System.out.println("用户列表");
		return userRepository.findAll();
	}

}
